package com.elitel.common.exception;

import com.elitel.common.ExceptionManagerUtil;
import com.elitel.frame.main.entity.SysException;
import com.elitel.frame.main.entity.vo.ExceptionVo;

import java.util.HashMap;
import java.util.Map;

/**
 * 异常处理类
 *
 * @author dingdaifu
 */
public class BaseException extends RuntimeException {

  private static final long serialVersionUID = -434104233779192938L;

  private static final String[] errorCode = {"110"};

  private ExceptionVo exceptionVO;

  private Map<String, Object> map;

  public BaseException() {
    super();
    this.map = new HashMap<>();
  }

  /**
   * @param exception 异常类
   * @param message 异常信息
   * @param mapException 异常表映射
   */
  public BaseException(
      Throwable exception,
      String message,
      String sqlException,
      Map<String, SysException> mapException) {
    super(message, exception);
    this.map = new HashMap<>();
    this.exceptionVO = ExceptionManagerUtil.getException((Exception) exception, mapException);
    if (Integer.valueOf(exceptionVO.getErrorType()) == 4) {
      map.put(sqlException, exceptionVO.getValue());
    }
  }

  public BaseException(
      Throwable exception, String sqlException, Map<String, SysException> mapException) {
    super(exception);
    this.map = new HashMap<>();
    this.exceptionVO = ExceptionManagerUtil.getException((Exception) exception, mapException);
    if (Integer.valueOf(exceptionVO.getErrorType()) == 5) {
      map.put(sqlException, exceptionVO.getValue());
    } else {
      map.put(exceptionVO.getDesc(), exceptionVO.getValue());
    }
  }

  public BaseException(Throwable exception, Map<String, SysException> mapException) {
    super(exception);
    this.exceptionVO = ExceptionManagerUtil.getException((Exception) exception, mapException);
  }

  public ExceptionVo getExceptionVO() {
    return exceptionVO;
  }

  public void setExceptionVO(ExceptionVo exceptionVO) {
    this.exceptionVO = exceptionVO;
  }

  public Map<String, Object> getMap() {
    return map;
  }

  public void setMap(Map<String, Object> map) {
    this.map = map;
  }
}
